package com.ruoyi.web.controller.paiban;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paiban.domain.Paibanbiao;
import com.ruoyi.paiban.service.IPaibanbiaoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排班Controller
 *
 * @author ruoyi
 * @date 2023-05-26
 */
@RestController
@RequestMapping("/system/paibanbiao")
public class PaibanbiaoController extends BaseController
{
    @Autowired
    private IPaibanbiaoService paibanbiaoService;

    /**
     * 查询排班列表-按月
     */
    @PreAuthorize("@ss.hasPermi('yggl:pbgl:list')")
    @GetMapping("/list")
    public TableDataInfo list(Paibanbiao paibanbiao)
    {
//        startPage();
        List<Paibanbiao> list = paibanbiaoService.selectPaibanbiaoList(paibanbiao);
        return getDataTable(list);
    }

    /**
     * 查询排班列表-按天
     */
    @GetMapping("/listbyday")
    public TableDataInfo listbyday(Paibanbiao paibanbiao)
    {
        startPage();
        List<Paibanbiao> list = paibanbiaoService.selectPaibanbiaoListByDay(paibanbiao);
        return getDataTable(list);
    }


    /**
     * 导出排班列表
     */
    @Log(title = "排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Paibanbiao paibanbiao)
    {
        List<Paibanbiao> list = paibanbiaoService.selectPaibanbiaoList(paibanbiao);
        ExcelUtil<Paibanbiao> util = new ExcelUtil<Paibanbiao>(Paibanbiao.class);
        util.exportExcel(response, list, "排班数据");
    }

    /**
     * 获取排班详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paibanbiaoService.selectPaibanbiaoById(id));
    }

    /**
     * 新增排班
     */
    @Log(title = "排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Paibanbiao paibanbiao)
    {
        return toAjax(paibanbiaoService.insertPaibanbiao(paibanbiao));
    }

    /**
     * 修改排班
     */
    @Log(title = "排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Paibanbiao paibanbiao)
    {
        return toAjax(paibanbiaoService.updatePaibanbiao(paibanbiao));
    }

    /**
     * 删除选择天排班
     */
    @Log(title = "删除选择天排班", businessType = BusinessType.DELETE)
    @DeleteMapping("/delbyday")
    public AjaxResult delbyday(@RequestBody Paibanbiao paibanbiao)
    {
        int rows = paibanbiaoService.deletePaibanbiaoByDay(paibanbiao);
        if(rows > 0){
            return AjaxResult.success("删除成功");
        }else{
            return AjaxResult.error("没有要删除的数据");
        }
    }

    /**
     * 删除排班
     */
    @Log(title = "排班", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paibanbiaoService.deletePaibanbiaoByIds(ids));
    }
}
